package com.emep.changzhi.analyse.http.aqi;


import com.emep.changzhi.analyse.entity.aqi.AqiNumberOfDays;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.aqi.AqiNumberOfDaysService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("statistics")
@Api(value="获取城市AQI的统计情况",tags={"获取城市AQI的统计情况"})
public class AqiNumberOfDaysController {
    @Autowired
    private AqiNumberOfDaysService aqiNumberOfDaysService;

    @ApiOperation(value="获取城市AQI的统计情况", notes="获取城市AQI的统计情况")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
    })
    @GetMapping(value = "city/aqi")
    public ResultBean<Map<String,Object>> findweather(){
        return new ResultBean<Map<String,Object>>(aqiNumberOfDaysService.findStandardAndNumberOfDay());
    }

    @ApiOperation(value="统计某一个国控站点在48小时之内6参数的折线图", notes="统计某一个国控站点在48小时之内6参数的折线图")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityCode", value = "行政区划code", required = true, dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "siteName", value = "国控站点", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "bysite")
    public ResultBean<Map<String,Object>> findbysite(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "cityCode","siteName");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            Map<String,Object> weathers = aqiNumberOfDaysService.findBysite(payload.get("cityCode").toString(),payload.get("siteName").toString());
            return result.ok(weathers);
        }
        return  result;
    }


    @ApiOperation(value="获取城市AQI的统计情况", notes="获取城市AQI的统计情况")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
    })
    @GetMapping(value = "aqi/month")
    public ResultBean<Map<String,Object>>  findapiByMonth(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload,"areaCode");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            Map<String,Object> map =aqiNumberOfDaysService.findapiByMonth(payload.get("areaCode").toString());
            return  result.ok(map);
        }

        return  result;
    }


    @ApiOperation(value="获取城市AQI的统计情况", notes="获取城市AQI的统计情况")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
    })
    @GetMapping(value = "aqi/year")
    public ResultBean<Map<String,Object>>  findapiByYear(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload);
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            Map<String,Object> map =aqiNumberOfDaysService.findapiByYear(payload.get("areaCode").toString());
            return  result.ok(map);
        }

        return  result;
    }
}
